The C++ Workshop by Dale Green Kurt Guntheroth and Shaun Ross Mitchell
Author:Dale Green, Kurt Guntheroth, and Shaun Ross Mitchell
Language: eng
Format: mobi
Publisher: Packt Publishing Pvt Ltd
Published: 2020-02-04T16:00:00+00:00
The next step is to begin entering the body of main(). First, declare an instance of numeric_list called l. This function-local variable will be destroyed when main() returns: numeric_list l;
Create a for loop to add five items to the list, and then print out the list: for (int i = 1; i < 6; ++i)
{
l.add(i);
}
l.print();
Declare a numeric_item pointer called p, and assign to p the value returned by l.find(4). The value in p is an unowned pointer. We already know find() will discover an item with this value because we added it moments ago. Output a message if the returned pointer is not nullptr, just to be sure: numeric_item* p = l.find(4);
if (p != nullptr)
cout << "found numeric_item 4" << endl;
That's it. When main() returns, p is still pointing to an item in l. p isn't deleted, but that's fine because p is an unowned pointer.
As main() returns, l's destructor is called. Since l has an owned pointer, l's destructor must delete anything it points to, which is the entire list.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8316)
Test-Driven Development with Java by Alan Mellor(6876)
Data Augmentation with Python by Duc Haba(6801)
Principles of Data Fabric by Sonia Mezzetta(6536)
Learn Blender Simulations the Right Way by Stephen Pearson(6442)
Microservices with Spring Boot 3 and Spring Cloud by Magnus Larsson(6299)
Hadoop in Practice by Alex Holmes(5969)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(5817)
RPA Solution Architect's Handbook by Sachin Sahgal(5701)
Big Data Analysis with Python by Ivan Marin(5436)
The Infinite Retina by Robert Scoble Irena Cronin(5399)
Life 3.0: Being Human in the Age of Artificial Intelligence by Tegmark Max(5164)
Pretrain Vision and Large Language Models in Python by Emily Webber(4400)
Infrastructure as Code for Beginners by Russ McKendrick(4171)
Functional Programming in JavaScript by Mantyla Dan(4050)
The Age of Surveillance Capitalism by Shoshana Zuboff(3967)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3884)
Embracing Microservices Design by Ovais Mehboob Ahmed Khan Nabil Siddiqui and Timothy Oleson(3684)
Applied Machine Learning for Healthcare and Life Sciences Using AWS by Ujjwal Ratan(3661)
